//
//  DYJingdianTuijianCell.swift
//  SheYangBigData
//
//  Created by 宋海胜 on 2021/1/4.
//  Copyright © 2021 叁拾叁. All rights reserved.
//


import UIKit

class DYJingdianTuijianCell: SYBaseCell , UICollectionViewDelegate, UICollectionViewDataSource{
    
    var collectionView: UICollectionView!
    var model: DYJingquDetailModel!
    var bgView: UIView = {
        let v: UIView = UIView()
        v.backgroundColor = UIColor(hex: 0x367FF6)
        v.layer.cornerRadius = 2
        return v
    }()
    
    let nameLb: UILabel = {
        let v:UILabel = UILabel()
        v.textColor = UIColor(hex: 0x1E1E1E)
        v.font = 17.autoBoldFontSize()
        v.text = "更多景点推荐"
        return v
    }()
    
    

    public func configureView(_ model: DYJingquDetailModel) {
        self.model = model
        self.collectionView.reloadData()
        if let c = model.scenicSpotList?.count
        {
            collectionView.snp.remakeConstraints { (make) in
                make.top.equalTo(nameLb.snp.bottom).offset(autoWidth(15.0))
                make.right.equalToSuperview().offset(-12)
                make.left.equalToSuperview().offset(12)
                make.height.equalTo(184.autoWidth()*CGFloat(c/2 + c%2))
                make.bottom.equalToSuperview().offset(autoWidth(-15.0))
            }
        }
    }
    
    
    override func initViews() {
        
        setCollectionView()
        contentView.addSubview(nameLb)
        contentView.addSubview(bgView)

        contentView.addSubview(collectionView)
        bgView.snp.makeConstraints { (make) in
            make.top.equalToSuperview().offset(16.0.autoWidth())
            make.left.equalToSuperview().offset(autoWidth(14.5))
            make.width.equalTo(4.0.autoWidth())
            make.height.equalTo(15.0.autoWidth())
        }
        nameLb.snp.makeConstraints { (make) in
            make.centerY.equalTo(bgView)
            make.left.equalTo(bgView.snp.right).offset(autoWidth(7.0))
            make.right.equalToSuperview().offset(autoWidth(-15.0))
            make.height.equalTo(16.0.autoWidth())
        }
        collectionView.snp.makeConstraints { (make) in
            make.top.equalTo(nameLb.snp.bottom).offset(autoWidth(15.0))
            make.right.equalToSuperview().offset(-12)
            make.left.equalToSuperview().offset(12)
            make.height.equalTo(174.autoWidth()*0)
            make.bottom.equalToSuperview().offset(autoWidth(-15.0))
        }
     
    }
    
    func setCollectionView() {
        
            
        let layout: UICollectionViewFlowLayout = UICollectionViewFlowLayout()
        let itemWidth = 170.0.autoWidth() + 5.0
        layout.itemSize = CGSize(width: itemWidth, height: 173.5.autoWidth())
        layout.minimumLineSpacing = 10
        layout.minimumInteritemSpacing = 1
        layout.scrollDirection = .vertical
        collectionView = UICollectionView(frame: CGRect.zero, collectionViewLayout: layout)
        collectionView.backgroundColor = .white
        collectionView.showsHorizontalScrollIndicator = false
        
        
        collectionView.delegate = self
        collectionView.dataSource = self
        collectionView.register(DYJingdianTuijianSubCell.self, forCellWithReuseIdentifier: NSStringFromClass(DYJingdianTuijianSubCell.self))
        self.addSubview(self.collectionView)
    }
    
    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        if let m = self.model, let c = m.scenicSpotList?.count {
            return c
        }
        return 0
    }
    
    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        let cell: DYJingdianTuijianSubCell? = collectionView.dequeueReusableCell(withReuseIdentifier: NSStringFromClass(DYJingdianTuijianSubCell.self), for: indexPath) as? DYJingdianTuijianSubCell
        if let m = model, let l = m.scenicSpotList?[indexPath.row] {
            cell?.configureView(l)
        }
        return cell!
    }
    
    func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
        let vc = DYJingquDetailViewController(self.model.scenicSpotList?[indexPath.row].id ?? "")
        self.currentVC.navigationController?.pushViewController(vc, animated: true)
    }
    
   
}



class DYMeishiTuijianCell: SYBaseCell , UICollectionViewDelegate, UICollectionViewDataSource{
    
    var collectionView: UICollectionView!
    var models: [DYTourRestaurantListModel] = []
    var bgView: UIView = {
        let v: UIView = UIView()
        v.backgroundColor = UIColor(hex: 0x367FF6)
        v.layer.cornerRadius = 2
        return v
    }()
    
    let nameLb: UILabel = {
        let v:UILabel = UILabel()
        v.textColor = UIColor(hex: 0x1E1E1E)
        v.font = 17.autoBoldFontSize()
        v.text = "更多推荐"
        return v
    }()
    
    public func configureView(_ models: [DYTourRestaurantListModel]) {
        self.models = models
        self.collectionView.reloadData()
        let c = models.count
            collectionView.snp.remakeConstraints { (make) in
                make.top.equalTo(nameLb.snp.bottom).offset(autoWidth(15.0))
                make.right.equalToSuperview().offset(-12)
                make.left.equalToSuperview().offset(12)
                make.height.equalTo(184.autoWidth()*CGFloat(c/2 + c%2))
                make.bottom.equalToSuperview().offset(autoWidth(-15.0))
            }
    }
    
    
    override func initViews() {
        
        setCollectionView()
        contentView.addSubview(nameLb)
        contentView.addSubview(bgView)

        contentView.addSubview(collectionView)
        bgView.snp.makeConstraints { (make) in
            make.top.equalToSuperview().offset(16.0.autoWidth())
            make.left.equalToSuperview().offset(autoWidth(14.5))
            make.width.equalTo(4.0.autoWidth())
            make.height.equalTo(15.0.autoWidth())
        }
        nameLb.snp.makeConstraints { (make) in
            make.centerY.equalTo(bgView)
            make.left.equalTo(bgView.snp.right).offset(autoWidth(7.0))
            make.right.equalToSuperview().offset(autoWidth(-15.0))
            make.height.equalTo(16.0.autoWidth())
        }
        collectionView.snp.makeConstraints { (make) in
            make.top.equalTo(nameLb.snp.bottom).offset(autoWidth(15.0))
            make.right.equalToSuperview().offset(-12)
            make.left.equalToSuperview().offset(12)
            make.height.equalTo(174.autoWidth()*0)
            make.bottom.equalToSuperview().offset(autoWidth(-15.0))
        }
     
    }
    
    func setCollectionView() {
        
            
        let layout: UICollectionViewFlowLayout = UICollectionViewFlowLayout()
        let itemWidth = 170.0.autoWidth() + 5.0
        layout.itemSize = CGSize(width: itemWidth, height: 173.5.autoWidth())
        layout.minimumLineSpacing = 10
        layout.minimumInteritemSpacing = 1
        layout.scrollDirection = .vertical
        collectionView = UICollectionView(frame: CGRect.zero, collectionViewLayout: layout)
        collectionView.backgroundColor = .white
        collectionView.showsHorizontalScrollIndicator = false
        
        
        collectionView.delegate = self
        collectionView.dataSource = self
        collectionView.register(DYJingdianTuijianSubCell.self, forCellWithReuseIdentifier: NSStringFromClass(DYJingdianTuijianSubCell.self))
        self.addSubview(self.collectionView)
    }
    
    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return self.models.count
    }
    
    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        let cell: DYJingdianTuijianSubCell? = collectionView.dequeueReusableCell(withReuseIdentifier: NSStringFromClass(DYJingdianTuijianSubCell.self), for: indexPath) as? DYJingdianTuijianSubCell
            cell?.configureMSView(models[indexPath.row])
        return cell!
    }
    
    func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
        let vc = DYMeishiDetailViewController(self.models[indexPath.row].id ?? "")
        self.currentVC.navigationController?.pushViewController(vc, animated: true)
    }
    
   
}



class DYZhusuTuijianCell: SYBaseCell , UICollectionViewDelegate, UICollectionViewDataSource{
    
    var collectionView: UICollectionView!
    var model: DYZSDetailModel!
    var bgView: UIView = {
        let v: UIView = UIView()
        v.backgroundColor = UIColor(hex: 0x367FF6)
        v.layer.cornerRadius = 2
        return v
    }()
    
    let nameLb: UILabel = {
        let v:UILabel = UILabel()
        v.textColor = UIColor(hex: 0x1E1E1E)
        v.font = 17.autoBoldFontSize()
        v.text = "更多景点推荐"
        return v
    }()
    
    

    public func configureView(_ model: DYZSDetailModel) {
        self.model = model
        self.collectionView.reloadData()
        if let c = model.tourHotelList?.count
        {
            collectionView.snp.remakeConstraints { (make) in
                make.top.equalTo(nameLb.snp.bottom).offset(autoWidth(15.0))
                make.right.equalToSuperview().offset(-12)
                make.left.equalToSuperview().offset(12)
                make.height.equalTo(184.autoWidth()*CGFloat(c/2 + c%2))
                make.bottom.equalToSuperview().offset(autoWidth(-15.0))
            }
        }
    }
    
    
    override func initViews() {
        
        setCollectionView()
        contentView.addSubview(nameLb)
        contentView.addSubview(bgView)

        contentView.addSubview(collectionView)
        bgView.snp.makeConstraints { (make) in
            make.top.equalToSuperview().offset(16.0.autoWidth())
            make.left.equalToSuperview().offset(autoWidth(14.5))
            make.width.equalTo(4.0.autoWidth())
            make.height.equalTo(15.0.autoWidth())
        }
        nameLb.snp.makeConstraints { (make) in
            make.centerY.equalTo(bgView)
            make.left.equalTo(bgView.snp.right).offset(autoWidth(7.0))
            make.right.equalToSuperview().offset(autoWidth(-15.0))
            make.height.equalTo(16.0.autoWidth())
        }
        collectionView.snp.makeConstraints { (make) in
            make.top.equalTo(nameLb.snp.bottom).offset(autoWidth(15.0))
            make.right.equalToSuperview().offset(-12)
            make.left.equalToSuperview().offset(12)
            make.height.equalTo(174.autoWidth()*0)
            make.bottom.equalToSuperview().offset(autoWidth(-15.0))
        }
     
    }
    
    func setCollectionView() {
        
            
        let layout: UICollectionViewFlowLayout = UICollectionViewFlowLayout()
        let itemWidth = 170.0.autoWidth() + 5.0
        layout.itemSize = CGSize(width: itemWidth, height: 173.5.autoWidth())
        layout.minimumLineSpacing = 10
        layout.minimumInteritemSpacing = 1
        layout.scrollDirection = .vertical
        collectionView = UICollectionView(frame: CGRect.zero, collectionViewLayout: layout)
        collectionView.backgroundColor = .white
        collectionView.showsHorizontalScrollIndicator = false
        
        
        collectionView.delegate = self
        collectionView.dataSource = self
        collectionView.register(DYJingdianTuijianSubCell.self, forCellWithReuseIdentifier: NSStringFromClass(DYJingdianTuijianSubCell.self))
        self.addSubview(self.collectionView)
    }
    
    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        if let m = self.model, let c = m.tourHotelList?.count {
            return c
        }
        return 0
    }
    
    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        let cell: DYJingdianTuijianSubCell? = collectionView.dequeueReusableCell(withReuseIdentifier: NSStringFromClass(DYJingdianTuijianSubCell.self), for: indexPath) as? DYJingdianTuijianSubCell
        if let m = model, let l = m.tourHotelList?[indexPath.row] {
            cell?.configureZSView(l)
        }
        return cell!
    }
    
    func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
        let vc = DYZhusuDetailViewController(self.model.tourHotelList?[indexPath.row].id ?? "")
        self.currentVC.navigationController?.pushViewController(vc, animated: true)
    }
    
   
}
